from django.db import models


class Room(models.Model):
    """视频会议房间"""
    STATUS = (
        (0, '无效'),
        (1, '有效'),
    )
    NUMS = (
        (1, '1'),
        (2, '2'),
        (3, '3'),
        (4, '4'),
        (5, '5'),
        (6, '6'),
    )
    description = models.CharField(verbose_name='房间名称', max_length=32, blank=True, null=True)
    secret = models.CharField(verbose_name='房间管理密码', max_length=32, blank=True, null=True)
    pin = models.CharField(verbose_name='加入房间密码', max_length=32, blank=True, null=True)
    is_private = models.BooleanField(verbose_name='私有房间', default=False, blank=True, null=True)
    allowed = models.CharField(verbose_name='允许的令牌', max_length=1024, blank=True, null=True)
    permanent = models.BooleanField(verbose_name='是否持久化', default=False, blank=True, null=True)
    numbers = models.IntegerField(verbose_name='人数', choices=NUMS, default=1, blank=True, null=True)
    status = models.IntegerField(verbose_name='状态', choices=STATUS, default=1, blank=True, null=True)
    update_time = models.DateTimeField(verbose_name='修改时间', auto_now=True)
    add_time = models.DateTimeField(verbose_name='添加时间', auto_now_add=True)

    def __str__(self):
        return self.description

    class Meta:
        verbose_name = '视频会议房间'
        verbose_name_plural = verbose_name


class VideoLoginUser(models.Model):
    """
    视频用户表
    """
    name = models.CharField(verbose_name='登录名', max_length=32, unique=True)
    real_name = models.CharField(verbose_name='姓名', max_length=32, blank=True, null=True)
    gender = models.CharField(verbose_name="性别",  max_length=4, choices=(("男", "男"), ("女", "女")), blank=True, null=True)
    password = models.CharField(verbose_name='密码', max_length=128, blank=True, null=True)
    telephone = models.CharField(verbose_name='手机', max_length=16, blank=True, null=True)
    update_time = models.DateTimeField(verbose_name='修改时间', auto_now=True)
    add_time = models.DateTimeField(verbose_name='添加时间', auto_now_add=True)

    def __str__(self):
        return self.real_name if self.real_name else self.name

    class Meta:
        verbose_name = '视频登录用户'
        verbose_name_plural = verbose_name
        ordering = ['-add_time']


class VideoUserInfo(models.Model):
    """视频用户"""
    SEX_CHOICE = (
        (1, '男'),
        (2, '女'),
        (0, '未知'),
    )

    openid = models.CharField(verbose_name='微信ID', max_length=120, blank=True, null=True)
    nickname = models.CharField(verbose_name='用户昵称', max_length=64, blank=True, null=True)
    name = models.CharField(verbose_name='姓名', max_length=32, blank=True, null=True)
    telephone = models.CharField(verbose_name='手机号码', max_length=18, blank=True, null=True)
    sex = models.IntegerField(verbose_name='性别', choices=SEX_CHOICE, blank=True, null=True)            # 值为1时是男性，值为2时是女性，值为0时是未知
    province = models.CharField(verbose_name='省份', max_length=64, blank=True, null=True)
    city = models.CharField(verbose_name='城市', max_length=64, blank=True, null=True)
    country = models.CharField(verbose_name='国家', max_length=64, blank=True, null=True)
    language = models.CharField(verbose_name='国家', max_length=12, blank=True, null=True)
    headimgurl = models.CharField(verbose_name='头像', max_length=240, blank=True, null=True)
    qr_scene_str = models.CharField(verbose_name='扫码场景描述', max_length=64, blank=True, null=True)
    role_id = models.IntegerField(verbose_name='角色ID', blank=True, null=True)
    update_time = models.DateTimeField(verbose_name='修改时间', auto_now=True)
    add_time = models.DateTimeField(verbose_name='添加时间', auto_now_add=True)

    def __str__(self):
        return self.nickname

    class Meta:
        verbose_name = '视频用户列表'
        verbose_name_plural = verbose_name
        ordering = ["-id"]
